"""
数据转储：Chip_Shear\Wire_pull\Wire_pull_QN\Wire_Shear\Wire_Shear_QN
    -> CTQ_push_pull_data_HX
"""
import pandas as pd
import numpy as np
from sqlalchemy import create_engine
import pyodbc

# 显示全体数据
pd.set_option('display.max_columns', None)

engine = create_engine(
    "mssql+pyodbc://qains:qains8100@172.18.65.31:1433/QualityDB?driver=ODBC+Driver+17+for+SQL+Server",
    fast_executemany=True)

# engine = create_engine(
#     "mssql+pyodbc://qatest:qatest@192.168.3.236:1433/SortingDB?driver=ODBC+Driver+17+for+SQL+Server",
#     fast_executemany=True)


def get_insert_sql(table_name, df):
    colnames = '[' + '],['.join(list(df.columns)) + ']'
    # print(colnames)
    values_lis = []

    def func1(sr):
        value_str = "("
        for value in list(sr.values):
            value = str(value)
            value = value.strip(' ')
            if value and value != 'None' and value != 'nan' and value != 'NaT':
                value_str = value_str + "'" + value + "',"
            else:
                value_str = value_str + 'Null' + ","
        value_str = value_str[: -1] + ")"
        values_lis.append(value_str)

    sql = ""
    df.apply(func1, axis=1)
    for i in range(0, len(values_lis) // 500 + 1):
        if len(values_lis) > (i + 1) * 500:
            values_str = ','.join(values_lis[i * 500: (i + 1) * 500])
        else:
            values_str = ','.join(values_lis[i * 500:])
        sql = sql + f"insert into {table_name} ({colnames}) values {values_str};"
    # values_str = ','.join(values_lis)
    # sql = f"insert into {self.table_name} ({colnames}) values {values_str};"
    # print(sql)
    # with open(main_filepath + r'\测试\sql.txt', 'w', encoding='utf-8') as f:
    #     f.write(sql)
    return sql


def GJ(conn, sql_cols):
    list1 = [f'Chip_shear{num}' for num in range(1, 61)]
    cursor = conn.cursor()
    sql = "SELECT DISTINCT * FROM Chip_shear"
    df = pd.read_sql(sql, engine)
    df = df.drop(columns=['列名'])
    df_pre = df[sql_cols]
    df_pre = df_pre.drop_duplicates()
    for i in df_pre.itertuples():
        df_down = pd.DataFrame()
        select_str = ''
        for col in sql_cols:
            if getattr(i, col):
                str_ = f"{col} = '{getattr(i, col)}' "
                select_str += 'AND ' + str_
            else:
                continue

        sql_time = "SELECT MAX(UpdateTime) FROM Chip_shear where 1=1 " + select_str
        time1 = pd.read_sql(sql_time, engine).iloc[0, 0]

        sql = "SELECT * FROM Chip_shear where 1=1 " + select_str
        all_list = sql_cols + list1
        df_s = pd.read_sql(sql, engine)
        df_s = df_s.drop(columns=['列名'])
        df_data = df_s.loc[:, all_list].drop_duplicates()
        print(time1)
        list_data = []
        if len(df_data) >= 2:
            for index1 in range(len(df_data)):
                list_data += list(df_data.loc[:, list1].iloc[index1].astype('float').values)
            list_final = [data for data in list_data if not np.isnan(data)]
            for i, data in zip(range(len(list_final)), list_final):
                num = 0
                mark = (i + 1) % 60
                if mark == 0:
                    num += 1
                df_down.loc[num, f'DATA{i + 1}'] = data
            df_s = df_s.loc[0:0, sql_cols]
            for i in range(len(df_down)):
                df_s = pd.concat([df_s, df_s], axis=0)
            # df_s = pd.DataFrame(df_s.loc[0, sql_cols])
            df_s = pd.concat([df_s, df_down], axis=1)
        else:
            for i in range(1, 61):
                df_s.rename(columns={f'Chip_shear{i}': f'DATA{i}'}, inplace=True)
        df_s['MEASURE_ITEM'] = '固晶推力'
        df_s['UpdateTime'] = time1
        # print(df_s)
        sql_I = get_insert_sql('CTQ_push_pull_data_HX', df_s)
        cursor.execute(sql_I)
    print('Chip_shear完成')


def HX_T(conn, sql_cols):
    list1 = []
    list2 = []
    list3 = []
    all_list = []
    for i in range(1, 61):
        j = i % 6
        if j == 2 or j == 1:
            list1.append(f'P_shear{i}')
            all_list.append(f'P_shear{i}')
        elif j == 3 or j == 4:
            list2.append(f'N_shear{i}')
            all_list.append(f'N_shear{i}')
        elif j == 5 or j == 0:
            list3.append(f'Bonding_shear{i}')
            all_list.append(f'Bonding_shear{i}')
    cursor = conn.cursor()
    sql = "SELECT DISTINCT * FROM Wire_shear"
    df = pd.read_sql(sql, engine)
    df_bef = df[sql_cols].drop_duplicates()
    for i in df_bef.itertuples():
        df_P = pd.DataFrame()
        df_N = pd.DataFrame()
        df_B = pd.DataFrame()
        select_str = ''
        for col in sql_cols:
            if getattr(i, col):
                str_ = f"{col} = '{getattr(i, col)}' "
                select_str += 'AND ' + str_
            else:
                continue

        sql_time = "SELECT MAX(UpdateTime) FROM Wire_shear where 1=1 " + select_str
        time1 = pd.read_sql(sql_time, engine).iloc[0, 0]
        print(time1)
        sql = "SELECT * FROM Wire_shear where 1=1 " + select_str
        df_s = pd.read_sql(sql, engine)
        # print(len(df_s))
        # print(df_s.loc[:, all_list])
        df_pre = df_s.loc[0:0, sql_cols]
        # print(df_pre)
        df_aft = df_s.loc[:, all_list].drop_duplicates()
        # print(len(df_aft))
        list_P = []
        list_N = []
        list_B = []
        if len(df_aft) >= 2:
            for index1 in range(len(df_aft)):
                list_P += list(df_aft.loc[:, list1].iloc[index1].astype('float').values)
                list_N += list(df_aft.loc[:, list2].iloc[index1].astype('float').values)
                list_B += list(df_aft.loc[:, list3].iloc[index1].astype('float').values)
        else:
            for index1 in range(len(df_aft)):
                list_P += list(df_aft.loc[:, list1].iloc[index1].astype('float').values)
                list_N += list(df_aft.loc[:, list2].iloc[index1].astype('float').values)
                list_B += list(df_aft.loc[:, list3].iloc[index1].astype('float').values)
        list_final_P = [data for data in list_P if not np.isnan(data)]
        list_final_N = [data for data in list_N if not np.isnan(data)]
        list_final_B = [data for data in list_B if not np.isnan(data)]

        for x in range(len(list_final_P)):
            num = 0
            mark = (x + 1) % 60
            if mark == 0:
                df_P.loc[num, f'DATA60'] = list_final_P[x]
                num += 1
            else:
                df_P.loc[num, f'DATA{mark}'] = list_final_P[x]
        df_P['MEASURE_ITEM'] = '焊线推力_P'
        df_P['UpdateTime'] = time1
        for p in range(len(df_P)):
            if len(df_P) == len(df_pre):
                break
            else:
                df_pre = pd.concat([df_pre, df_pre], axis=0)
                df_pre = df_pre.reset_index(drop=True)
        df_P = pd.concat([df_pre, df_P], axis=1)

        for y in range(len(list_final_N)):
            num = 0
            mark = (y + 1) % 60
            if mark == 0:
                df_N.loc[num, f'DATA60'] = list_final_N[y]
                num += 1
            else:
                df_N.loc[num, f'DATA{mark}'] = list_final_N[y]
        df_N['MEASURE_ITEM'] = '焊线推力_N'
        df_N['UpdateTime'] = time1
        for n in range(len(df_N)):
            if len(df_N) == len(df_pre):
                break
            else:
                df_pre = pd.concat([df_pre, df_pre], axis=0)
                df_pre = df_pre.reset_index(drop=True)
        df_N = pd.concat([df_pre, df_N], axis=1)

        for z in range(len(list_final_B)):
            num = 0
            mark = (z + 1) % 60
            if mark == 0:
                df_B.loc[num, f'DATA60'] = list_final_B[z]
                num += 1
            else:
                df_B.loc[num, f'DATA{mark}'] = list_final_B[z]
        df_B['MEASURE_ITEM'] = '焊线推力_B'
        df_B['UpdateTime'] = time1
        for b in range(len(df_B)):
            if len(df_B) == len(df_pre):
                break
            else:
                df_pre = pd.concat([df_pre, df_pre], axis=0)
                df_pre = df_pre.reset_index(drop=True)
        df_B = pd.concat([df_pre, df_B], axis=1)

        sql_P = get_insert_sql('CTQ_push_pull_data_HX', df_P)
        sql_N = get_insert_sql('CTQ_push_pull_data_HX', df_N)
        sql_B = get_insert_sql('CTQ_push_pull_data_HX', df_B)
        cursor.execute(sql_P)
        cursor.execute(sql_N)
        cursor.execute(sql_B)
    print('Wire_shear完成')


def HX_T_QN(conn, sql_cols):
    list1 = []
    list2 = []
    list3 = []
    list4 = []
    list5 = []
    all_list = []
    for i in range(1, 51):
        j = i % 10
        if j == 2 or j == 1:
            list1.append(f'P_shear{i}')
            all_list.append(f'P_shear{i}')
        elif j == 3 or j == 4:
            list2.append(f'N_shear{i}')
            all_list.append(f'N_shear{i}')
        elif j == 5 or j == 6:
            list3.append(f'Bonding_shear{i}')
            all_list.append(f'Bonding_shear{i}')
        elif j == 7 or j == 8:
            list4.append(f'QN_P_shear{i}')
            all_list.append(f'QN_P_shear{i}')
        elif j == 9 or j == 0:
            list5.append(f'QN_N_shear{i}')
            all_list.append(f'QN_N_shear{i}')
    cursor = conn.cursor()
    sql = "SELECT DISTINCT * FROM Wire_shear_QN"
    df = pd.read_sql(sql, engine)
    df_bef = df[sql_cols].drop_duplicates()
    for i in df_bef.itertuples():
        df_P = pd.DataFrame()
        df_N = pd.DataFrame()
        df_B = pd.DataFrame()
        df_QN_P = pd.DataFrame()
        df_QN_N = pd.DataFrame()
        select_str = ''
        for col in sql_cols:
            if getattr(i, col):
                str_ = f"{col} = '{getattr(i, col)}' "
                select_str += 'AND ' + str_
            else:
                continue

        sql_time = "SELECT MAX(UpdateTime) FROM Wire_shear_QN where 1=1 " + select_str
        time1 = pd.read_sql(sql_time, engine).iloc[0, 0]
        print(time1)
        sql = "SELECT * FROM Wire_shear_QN where 1=1 " + select_str
        df_s = pd.read_sql(sql, engine)
        # print(len(df_s))
        # print(df_s.loc[:, all_list])
        df_pre = df_s.loc[0:0, sql_cols]
        # print(df_pre)
        df_aft = df_s.loc[:, all_list].drop_duplicates()
        # print(len(df_aft))
        list_P = []
        list_N = []
        list_B = []
        list_QN_P = []
        list_QN_N = []
        for index1 in range(len(df_aft)):
            list_P += list(df_aft.loc[:, list1].iloc[index1].astype('float').values)
            list_N += list(df_aft.loc[:, list2].iloc[index1].astype('float').values)
            list_B += list(df_aft.loc[:, list3].iloc[index1].astype('float').values)
            list_QN_P += list(df_aft.loc[:, list4].iloc[index1].astype('float').values)
            list_QN_N += list(df_aft.loc[:, list5].iloc[index1].astype('float').values)
        list_final_P = [data for data in list_P if not np.isnan(data)]
        list_final_N = [data for data in list_N if not np.isnan(data)]
        list_final_B = [data for data in list_B if not np.isnan(data)]
        list_final_QN_P = [data for data in list_QN_P if not np.isnan(data)]
        list_final_QN_N = [data for data in list_QN_N if not np.isnan(data)]

        for p in range(len(list_final_P)):
            num = 0
            mark = (p + 1) % 60
            if mark == 0:
                num += 1
            df_P.loc[num, f'DATA{p + 1}'] = list_final_P[p]
        df_P['MEASURE_ITEM'] = '焊线推力_P'
        df_P['UpdateTime'] = time1
        for p in range(len(df_P)):
            if len(df_P) == len(df_pre):
                break
            else:
                df_pre = pd.concat([df_pre, df_pre], axis=0)
                df_pre = df_pre.reset_index(drop=True)
        df_P = pd.concat([df_pre, df_P], axis=1)

        for n in range(len(list_final_N)):
            num = 0
            mark = (n + 1) % 60
            if mark == 0:
                num += 1
            df_N.loc[num, f'DATA{mark}'] = list_final_N[n]
        df_N['MEASURE_ITEM'] = '焊线推力_N'
        df_N['UpdateTime'] = time1
        for n in range(len(df_N)):
            if len(df_N) == len(df_pre):
                break
            else:
                df_pre = pd.concat([df_pre, df_pre], axis=0)
                df_pre = df_pre.reset_index(drop=True)
        df_N = pd.concat([df_pre, df_N], axis=1)

        for b in range(len(list_final_B)):
            num = 0
            mark = (b + 1) % 60
            if mark == 0:
                num += 1
            df_B.loc[num, f'DATA{mark}'] = list_final_B[b]
        df_B['MEASURE_ITEM'] = '焊线推力_B'
        df_B['UpdateTime'] = time1
        for b in range(len(df_B)):
            if len(df_B) == len(df_pre):
                break
            else:
                df_pre = pd.concat([df_pre, df_pre], axis=0)
                df_pre = df_pre.reset_index(drop=True)
        df_B = pd.concat([df_pre, df_B], axis=1)

        for qn_p in range(len(list_final_QN_P)):
            num = 0
            mark = (qn_p + 1) % 60
            if mark == 0:
                num += 1
            df_QN_P.loc[num, f'DATA{mark}'] = list_final_QN_P[qn_p]
        df_QN_P['MEASURE_ITEM'] = '焊线推力_QN_P'
        df_QN_P['UpdateTime'] = time1
        for qn_p in range(len(df_QN_P)):
            if len(df_QN_P) == len(df_pre):
                break
            else:
                df_pre = pd.concat([df_pre, df_pre], axis=0)
                df_pre = df_pre.reset_index(drop=True)
        df_QN_P = pd.concat([df_pre, df_QN_P], axis=1)

        for qn_n in range(len(list_final_QN_N)):
            num = 0
            mark = (qn_n + 1) % 60
            if mark == 0:
                num += 1
            df_QN_N.loc[num, f'DATA{mark}'] = list_final_QN_N[qn_n]
        df_QN_N['MEASURE_ITEM'] = '焊线推力_QN_N'
        df_QN_N['UpdateTime'] = time1
        for qn_n in range(len(df_QN_N)):
            if len(df_QN_N) == len(df_pre):
                break
            else:
                df_pre = pd.concat([df_pre, df_pre], axis=0)
                df_pre = df_pre.reset_index(drop=True)
        df_QN_N = pd.concat([df_pre, df_QN_N], axis=1)

        sql_P = get_insert_sql('CTQ_push_pull_data_HX', df_P)
        sql_N = get_insert_sql('CTQ_push_pull_data_HX', df_N)
        sql_B = get_insert_sql('CTQ_push_pull_data_HX', df_B)
        sql_QN_P = get_insert_sql('CTQ_push_pull_data_HX', df_QN_P)
        sql_QN_N = get_insert_sql('CTQ_push_pull_data_HX', df_QN_N)
        cursor.execute(sql_P)
        cursor.execute(sql_N)
        cursor.execute(sql_B)
        cursor.execute(sql_QN_P)
        cursor.execute(sql_QN_N)
        conn.commit()
    print('Wire_shear_QN完成')


def HX_L(conn, sql_cols):
    list1 = []
    list2 = []
    all_list = []
    for i in range(1, 61):
        j = i % 6
        if j == 2 or j == 1 or j == 3 or j == 4:
            list1.append(f'B_open_chip_to_chip{i}')
            all_list.append(f'B_open_chip_to_chip{i}')
        elif j == 5 or j == 0:
            list2.append(f'B_open_chip_to_bonding{i}')
            all_list.append(f'B_open_chip_to_bonding{i}')
    cursor = conn.cursor()
    sql = "SELECT DISTINCT * FROM Wire_pull"
    df = pd.read_sql(sql, engine)
    df_bef = df[sql_cols].drop_duplicates()
    for i in df_bef.itertuples():
        df_P = pd.DataFrame()
        df_B = pd.DataFrame()
        select_str = ''
        for col in sql_cols:
            if getattr(i, col):
                str_ = f"{col} = '{getattr(i, col)}' "
                select_str += 'AND ' + str_
            else:
                continue

        sql_time = "SELECT MAX(UpdateTime) FROM Wire_pull where 1=1 " + select_str
        time1 = pd.read_sql(sql_time, engine).iloc[0, 0]
        print(time1)
        sql = "SELECT * FROM Wire_pull where 1=1 " + select_str
        df_s = pd.read_sql(sql, engine)
        # print(len(df_s))
        # print(df_s.loc[:, all_list])
        df_pre = df_s.loc[0:0, sql_cols]
        # print(df_pre)
        df_aft = df_s.loc[:, all_list].drop_duplicates()
        # print(len(df_aft))
        list_P = []
        list_B = []
        for index1 in range(len(df_aft)):
            list_P += list(df_aft.loc[:, list1].iloc[index1].astype('float').values)
            list_B += list(df_aft.loc[:, list2].iloc[index1].astype('float').values)
        list_final_P = [data for data in list_P if not np.isnan(data)]
        list_final_B = [data for data in list_B if not np.isnan(data)]

        for x in range(len(list_final_P)):
            num = 0
            mark = (x + 1) % 60
            if mark == 0:
                df_P.loc[num, f'DATA60'] = list_final_P[x]
                num += 1
            else:
                df_P.loc[num, f'DATA{mark}'] = list_final_P[x]
        df_P['MEASURE_ITEM'] = '焊线拉力_chip'
        df_P['UpdateTime'] = time1
        for p in range(len(df_P)):
            if len(df_P) == len(df_pre):
                break
            else:
                df_pre = pd.concat([df_pre, df_pre], axis=0)
                df_pre = df_pre.reset_index(drop=True)
        df_P = pd.concat([df_pre, df_P], axis=1)

        for z in range(len(list_final_B)):
            num = 0
            mark = (z + 1) % 60
            if mark == 0:
                df_B.loc[num, f'DATA60'] = list_final_B[z]
                num += 1
            else:
                df_B.loc[num, f'DATA{mark}'] = list_final_B[z]
        df_B['MEASURE_ITEM'] = '焊线拉力_B'
        df_B['UpdateTime'] = time1
        for b in range(len(df_B)):
            if len(df_B) == len(df_pre):
                break
            else:
                df_pre = pd.concat([df_pre, df_pre], axis=0)
                df_pre = df_pre.reset_index(drop=True)
        df_B = pd.concat([df_pre, df_B], axis=1)

        sql_P = get_insert_sql('CTQ_push_pull_data_HX', df_P)
        sql_B = get_insert_sql('CTQ_push_pull_data_HX', df_B)
        cursor.execute(sql_P)
        cursor.execute(sql_B)
        conn.commit()
    print('Wire_pull完成')


def HX_L_QN(conn, sql_cols):
    list1 = []
    list2 = []
    list3 = []
    all_list = []
    for i in range(1, 41):
        j = i % 8
        if j == 2 or j == 1 or j == 3 or j == 4:
            list1.append(f'B_open_chip_to_chip{i}')
            all_list.append(f'B_open_chip_to_chip{i}')
        elif j == 5 or j == 6:
            list2.append(f'B_open_chip_to_bonding{i}')
            all_list.append(f'B_open_chip_to_bonding{i}')
        elif j == 7 or j == 0:
            list3.append(f'QN_open_chip_to_chip{i}')
            all_list.append(f'QN_open_chip_to_chip{i}')
    cursor = conn.cursor()
    sql = "SELECT DISTINCT * FROM Wire_pull_QN"
    df = pd.read_sql(sql, engine)
    df_bef = df[sql_cols].drop_duplicates()
    for i in df_bef.itertuples():
        df_P = pd.DataFrame()
        df_B = pd.DataFrame()
        df_QN = pd.DataFrame()
        select_str = ''
        for col in sql_cols:
            if getattr(i, col):
                str_ = f"{col} = '{getattr(i, col)}' "
                select_str += 'AND ' + str_
            else:
                continue

        sql_time = "SELECT MAX(UpdateTime) FROM Wire_pull_QN where 1=1 " + select_str
        time1 = pd.read_sql(sql_time, engine).iloc[0, 0]
        print(time1)
        sql = "SELECT * FROM Wire_pull_QN where 1=1 " + select_str
        df_s = pd.read_sql(sql, engine)
        # print(len(df_s))
        # print(df_s.loc[:, all_list])
        df_pre = df_s.loc[0:0, sql_cols]
        # print(df_pre)
        df_aft = df_s.loc[:, all_list].drop_duplicates()
        # print(len(df_aft))
        list_P = []
        list_B = []
        list_QN = []
        for index1 in range(len(df_aft)):
            list_P += list(df_aft.loc[:, list1].iloc[index1].astype('float').values)
            list_B += list(df_aft.loc[:, list2].iloc[index1].astype('float').values)
            list_QN += list(df_aft.loc[:, list3].iloc[index1].astype('float').values)
        list_final_P = [data for data in list_P if not np.isnan(data)]
        list_final_B = [data for data in list_B if not np.isnan(data)]
        list_final_QN = [data for data in list_QN if not np.isnan(data)]

        for x in range(len(list_final_P)):
            num = 0
            mark = (x + 1) % 60
            if mark == 0:
                df_P.loc[num, f'DATA60'] = list_final_P[x]
                num += 1
            else:
                df_P.loc[num, f'DATA{mark}'] = list_final_P[x]
        df_P['MEASURE_ITEM'] = '焊线拉力_chip'
        df_P['UpdateTime'] = time1
        for p in range(len(df_P)):
            if len(df_P) == len(df_pre):
                break
            else:
                df_pre = pd.concat([df_pre, df_pre], axis=0)
                df_pre = df_pre.reset_index(drop=True)
        df_P = pd.concat([df_pre, df_P], axis=1)

        for y in range(len(list_final_B)):
            num = 0
            mark = (y + 1) % 60
            if mark == 0:
                df_B.loc[num, f'DATA60'] = list_final_B[y]
                num += 1
            else:
                df_B.loc[num, f'DATA{mark}'] = list_final_B[y]
        df_B['MEASURE_ITEM'] = '焊线拉力_B'
        df_B['UpdateTime'] = time1
        for b in range(len(df_B)):
            if len(df_B) == len(df_pre):
                break
            else:
                df_pre = pd.concat([df_pre, df_pre], axis=0)
                df_pre = df_pre.reset_index(drop=True)
        df_B = pd.concat([df_pre, df_B], axis=1)

        for z in range(len(list_final_QN)):
            num = 0
            mark = (z + 1) % 60
            if mark == 0:
                df_QN.loc[num, f'DATA60'] = list_final_QN[z]
                num += 1
            else:
                df_QN.loc[num, f'DATA{mark}'] = list_final_QN[z]
        df_QN['MEASURE_ITEM'] = '焊线拉力_QN'
        df_QN['UpdateTime'] = time1
        for qn in range(len(df_QN)):
            if len(df_QN) == len(df_pre):
                break
            else:
                df_pre = pd.concat([df_pre, df_pre], axis=0)
                df_pre = df_pre.reset_index(drop=True)
        df_QN = pd.concat([df_pre, df_QN], axis=1)

        sql_P = get_insert_sql('CTQ_push_pull_data_HX', df_P)
        sql_B = get_insert_sql('CTQ_push_pull_data_HX', df_B)
        sql_QN = get_insert_sql('CTQ_push_pull_data_HX', df_QN)
        cursor.execute(sql_P)
        cursor.execute(sql_B)
        cursor.execute(sql_QN)
        conn.commit()
    print('Wire_pull_QN完成')


if __name__ == '__main__':
    conn = pyodbc.connect(
        DRIVER='{SQL SERVER}',
        SERVER='172.18.65.31',
        DATABASE='QualityDB',
        uid='qains',
        pwd='qains8100'
        # SERVER='192.168.3.236',
        # DATABASE='SortingDB',
        # uid='qatest',
        # pwd='qatest'
    )
    sql_cols = ['UserID', 'MoID', 'TestDate', 'TestTime', 'TestNo', 'Operator', 'Class', 'MachineID', 'WireDiameter',
                'ChipSize', 'DB_glue', 'LoadUnit', 'Sensor', 'TestMethod', 'AcceptanceVlaue',
                'TestingSpeed', 'ShearHeight']
    try:
        # GJ(conn, sql_cols)    # 固晶推力
        # HX_T(conn, sql_cols)  # 焊线推力
        # HX_T_QN(conn, sql_cols)  # 焊线推力-齐纳
        # HX_L(conn, sql_cols)  # 焊线拉力
        HX_L_QN(conn, sql_cols)  # 焊线拉力-齐纳
        conn.commit()
    except Exception as e:
        conn.rollback()
        print(e)
    finally:
        conn.close()
